package com.gbs.info2;

import com.gbs.info2.obj.VehicleMobile;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Base64;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class DetailView extends Activity {
	private VehicleMobile vehicleMobile;
	private ImageView vehiclePhoto;
	private TextView detailTitle, detailECV, detailFuelType,
			detailLocationType, detailPin, detailSpecification, detailFailures;
	private CheckBox detailAlarm, detailCetralLock, detailRemoteControl, detailSpareKeys;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detail);

		Bundle bundle = getIntent().getExtras();
		this.vehicleMobile = (VehicleMobile) bundle.get("vehicleMobile");

		vehiclePhoto = (ImageView) findViewById(R.id.detailVehiclePhoto);
		detailTitle = (TextView) findViewById(R.id.detailTitle);
		detailECV = (TextView) findViewById(R.id.detailECV);
		detailFuelType = (TextView) findViewById(R.id.detailFuelType);
		detailLocationType = (TextView) findViewById(R.id.detailLocationType);
		detailPin = (TextView) findViewById(R.id.detailPin);
		detailSpecification = (TextView) findViewById(R.id.detailSpecification);
		detailFailures = (TextView) findViewById(R.id.detailFailures);
		detailAlarm = (CheckBox)findViewById(R.id.detailAlarm);
		detailCetralLock = (CheckBox)findViewById(R.id.detailCentralLock);
		detailRemoteControl = (CheckBox)findViewById(R.id.detailRemoteControl);
		detailSpareKeys = (CheckBox)findViewById(R.id.detailSpareKeys);

		if (vehiclePhoto != null && vehicleMobile.getVehiclePhoto() != null) {
			byte[] bloc = Base64.decode(vehicleMobile.getVehiclePhoto(),
					Base64.DEFAULT);
			Bitmap bmp = BitmapFactory.decodeByteArray(bloc, 0, bloc.length);
			vehiclePhoto.setImageBitmap(bmp);
		}
		String separator = ": ";

		detailTitle.setText(getString(R.string.title) + separator
				+ vehicleMobile.getTitle());
		detailECV.setText(getString(R.string.ecv) + separator
				+ vehicleMobile.getEcv());
		detailFuelType.setText(getString(R.string.fuelType) + separator
				+ vehicleMobile.getFuelType());
		detailLocationType.setText(getString(R.string.locationType) + separator
				+ vehicleMobile.getLocationType());
		detailPin.setText(getString(R.string.pin) + separator
				+ vehicleMobile.getPin());
		detailSpecification.setText(getString(R.string.specification)
				+ separator + vehicleMobile.getSpecification());
		detailFailures.setText(getString(R.string.failures) + separator
				+ vehicleMobile.getFailures());
		detailAlarm.setText(getString(R.string.alarm));
		detailAlarm.setChecked(intToBoolean(vehicleMobile.getAlarm()));
		detailCetralLock.setText(getString(R.string.centralLock));
		detailCetralLock.setChecked(intToBoolean(vehicleMobile.getCentralLock()));
		detailRemoteControl.setText(getString(R.string.remoteControl));
		detailRemoteControl.setChecked(intToBoolean(vehicleMobile.getRemoteControl()));
		detailSpareKeys.setText(getString(R.string.spareKeys));
		detailSpareKeys.setChecked(intToBoolean(vehicleMobile.getSpareKeys()));
	}
	
	private boolean intToBoolean (int i){
		if (i ==1)return true;
		else {
			return false;
		}
		
	}
}
